/*
 * lala.java
 *
 * Created on December 20, 2007, 11:01 AM
 */

package erreAga.view.HoraExtra;

import javax.swing.JOptionPane;

import erreAga.dao.DaoException;
import erreAga.eb.Funcionario;
import erreAga.eb.HoraExtra;
import erreAga.service.ErreAgaService;
import erreAga.service.impl.ErreAgaServiceImpl;
import erreAga.ws.cliente.ClienteWebService;
import erreAga.ws.cliente.impl.ClienteWebServiceImpl;

/**
 *
 * @author helder
 */
public class CadastroHoraExtra extends javax.swing.JFrame {

  /**
   *
   */
  private static final long serialVersionUID = 3312082246982256708L;

  /** Creates new form lala */
  public CadastroHoraExtra() {
    initComponents();
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated
  // Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jSeparator1 = new javax.swing.JSeparator();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    buttonGravar = new javax.swing.JButton();
    buttonCalcular = new javax.swing.JButton();
    jSeparator2 = new javax.swing.JSeparator();
    diasApos8 = new javax.swing.JTextField();
    diasApos10 = new javax.swing.JTextField();
    sabChegados8 = new javax.swing.JTextField();
    sabChegados10 = new javax.swing.JTextField();
    qtdeFolgasMes = new javax.swing.JTextField();
    qtdeMinApos18 = new javax.swing.JTextField();
    jTextField1 = new javax.swing.JTextField();

    // setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setName("Form"); // NOI18N

    jLabel1.setText("Cadastro de Horas Extras"); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N

    jSeparator1.setName("jSeparator1"); // NOI18N

    jLabel2.setText("Qtde de dias chegados após as 8h:"); // NOI18N
    jLabel2.setName("jLabel2"); // NOI18N

    jLabel3.setText("Qtde de dias chegados após as 10h:"); // NOI18N
    jLabel3.setName("jLabel3"); // NOI18N

    jLabel4.setText("Qtde de sábados chegados as 8h:"); // NOI18N
    jLabel4.setName("jLabel4"); // NOI18N

    jLabel5.setText("Qtde de sábados chegados as 10h:"); // NOI18N
    jLabel5.setName("jLabel5"); // NOI18N

    jLabel6.setText("Qtde de folgas no mês:"); // NOI18N
    jLabel6.setName("jLabel6"); // NOI18N

    jLabel7.setText("Qtde de minutos após as 18h:"); // NOI18N
    jLabel7.setName("jLabel7"); // NOI18N

    jLabel8.setText("Funcionário:"); // NOI18N
    jLabel8.setName("jLabel8"); // NOI18N

    buttonGravar.setText("Gravar"); // NOI18N
    buttonGravar.setName("buttonGravar"); // NOI18N
    buttonGravar.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonGravarActionPerformed(evt);
      }
    });

    buttonCalcular.setText("Calcular"); // NOI18N
    buttonCalcular.setName("buttonCalcular"); // NOI18N
    buttonCalcular.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonCalcularActionPerformed(evt);
      }
    });

    jSeparator2.setName("jSeparator2"); // NOI18N

    // diasApos8.setText(resourceMap.getString("diasApos8.text")); // NOI18N
    diasApos8.setName("diasApos8"); // NOI18N

    // diasApos10.setText(resourceMap.getString("diasApos10.text")); // NOI18N
    diasApos10.setName("diasApos10"); // NOI18N

    // sabChegados8.setText(resourceMap.getString("sabChegados8.text")); //
    // NOI18N
    sabChegados8.setName("sabChegados8"); // NOI18N

    // sabChegados10.setText(resourceMap.getString("sabChegados10.text")); //
    // NOI18N
    sabChegados10.setName("sabChegados10"); // NOI18N

    // qtdeFolgasMes.setText(resourceMap.getString("qtdeFolgasMes.text")); //
    // NOI18N
    qtdeFolgasMes.setName("qtdeFolgasMes"); // NOI18N

    // qtdeMinApos18.setText(resourceMap.getString("qtdeMinApos18.text")); //
    // NOI18N
    qtdeMinApos18.setName("qtdeMinApos18"); // NOI18N

    // jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
    jTextField1.setName("jTextField1"); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
        getContentPane());
    getContentPane().setLayout(layout);
    layout
        .setHorizontalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jSeparator2,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 388,
                                Short.MAX_VALUE)
                            .addComponent(jSeparator1,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 388,
                                Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(buttonCalcular)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(buttonGravar))
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.LEADING,
                                layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        114,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.LEADING,
                                layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                layout
                                                    .createSequentialGroup()
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                            .addComponent(
                                                                jLabel6)
                                                            .addComponent(
                                                                jLabel5)
                                                            .addComponent(
                                                                jLabel7))
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(
                                                                qtdeFolgasMes,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                75,
                                                                Short.MAX_VALUE)
                                                            .addComponent(
                                                                qtdeMinApos18,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                75,
                                                                Short.MAX_VALUE)
                                                            .addComponent(
                                                                sabChegados10,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                75,
                                                                Short.MAX_VALUE)))
                                            .addGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                layout
                                                    .createSequentialGroup()
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                            .addComponent(
                                                                jLabel3)
                                                            .addComponent(
                                                                jLabel4)
                                                            .addComponent(
                                                                jLabel2))
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                false)
                                                            .addComponent(
                                                                sabChegados8,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                75,
                                                                Short.MAX_VALUE)
                                                            .addComponent(
                                                                diasApos10)
                                                            .addComponent(
                                                                diasApos8))))
                                    .addGap(51, 51, 51))).addContainerGap()));
    layout
        .setVerticalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1)
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jSeparator1,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel3).addGap(18, 18, 18)
                                    .addComponent(jLabel4))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(diasApos8,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(diasApos10,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18).addComponent(
                                        sabChegados8,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        18,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout.createParallelGroup(
                            javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5).addComponent(sabChegados10,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18).addGroup(
                        layout.createParallelGroup(
                            javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6).addComponent(qtdeFolgasMes,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout.createParallelGroup(
                            javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7).addComponent(qtdeMinApos18,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18).addComponent(jSeparator2,
                        javax.swing.GroupLayout.DEFAULT_SIZE, 1,
                        Short.MAX_VALUE).addGap(27, 27, 27).addGroup(
                        layout.createParallelGroup(
                            javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8).addComponent(jTextField1,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(48, 48, 48).addGroup(
                        layout.createParallelGroup(
                            javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(buttonGravar).addComponent(
                                buttonCalcular)).addContainerGap()));

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void buttonGravarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_buttonGravarActionPerformed
    // TODO add your handling code here:

    ErreAgaService erreAgaService = new ErreAgaServiceImpl();

    Funcionario funcionario = new Funcionario();

    try {
      funcionario = erreAgaService.getFuncionario(Integer
          .parseInt(this.jTextField1.getText()));
    } catch (NumberFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DaoException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    HoraExtra hora = new HoraExtra();

    hora.setFuncionario(funcionario);

    hora.setQuantidadeDiasChegadaAs10h(Integer.parseInt(this.diasApos10
        .getText()));
    hora.setQuantidadeDiasChegadaAs8h(Integer
        .parseInt(this.diasApos8.getText()));

    hora.setQuantidadeFolgasMes(Integer.parseInt(this.qtdeFolgasMes.getText()));
    hora.setQuantidadeMinutosApos18h(Integer.parseInt(this.qtdeMinApos18
        .getText()));
    hora.setQuantidadeSabadosChegadaAs10h(Integer.parseInt(this.sabChegados10
        .getText()));
    hora.setQuantidadeSabadosChegadaAs8h(Integer.parseInt(this.sabChegados8
        .getText()));

    try {
      erreAgaService.saveHoraExtra(hora);
    } catch (DaoException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    this.setVisible(false);

  }// GEN-LAST:event_buttonGravarActionPerformed

  private void buttonCalcularActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_buttonCalcularActionPerformed
    // TODO add your handling code here:

    ClienteWebService clienteWebService = new ClienteWebServiceImpl();

    Integer valorHoraExtra = clienteWebService.calculaHoraExtras(Integer
        .parseInt(this.diasApos8.getText()), Integer.parseInt(this.diasApos10
        .getText()), Integer.parseInt(this.sabChegados8.getText()), Integer
        .parseInt(this.sabChegados10.getText()), Integer
        .parseInt(this.qtdeFolgasMes.getText()), Integer
        .parseInt(this.qtdeMinApos18.getText()));

    JOptionPane.showMessageDialog(null, "Hora extra é igual a: "
        + valorHoraExtra, "Calculo de Hora Extra", JOptionPane.OK_OPTION
        +JOptionPane.INFORMATION_MESSAGE);

  }// GEN-LAST:event_buttonCalcularActionPerformed

  /**
   * @param args
   *          the command line arguments
   */
  /*
   * public static void main(String args[]) {
   * java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new
   * CadastroHoraExtra().setVisible(true); } }); }
   */
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton buttonCalcular;
  private javax.swing.JButton buttonGravar;
  private javax.swing.JTextField diasApos10;
  private javax.swing.JTextField diasApos8;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JSeparator jSeparator1;
  private javax.swing.JSeparator jSeparator2;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField qtdeFolgasMes;
  private javax.swing.JTextField qtdeMinApos18;
  private javax.swing.JTextField sabChegados10;
  private javax.swing.JTextField sabChegados8;
  // End of variables declaration//GEN-END:variables

}
